﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace Promocot.Models
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
    public class ValidateEmailAttribute : RegularExpressionAttribute
    {
       private const string pattern = @"^\w+([-+.]*[\w-]+)*@(\w+([-.]?\w+)){1,}\.\w{2,4}$";

    static ValidateEmailAttribute()
    {
        // Necesarrio para permitir la validacion del lado del cliente
        DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(ValidateEmailAttribute), typeof(RegularExpressionAttributeAdapter));
    }

    public ValidateEmailAttribute()
        : base(pattern){ }
    }
}
